package leetcode;

import java.util.HashSet;
import java.util.Iterator;

public class HashSetTest {

    public static void main(String[] args) {
        HashSet hs = new HashSet();
        Student s1 = new Student(1, "zhangsan");
        Student s2 = new Student(2, "lisi");
        Student s3 = new Student(3, "wangwu");
        Student s4 = new Student(1, "zhangsan");
        String s5 = "hello";
        String s6 = "hello";
//        hs.add(new Student(1, "zhangsan"));
//        hs.add(new Student(2, "lisi"));
//        hs.add(new Student(3, "wangwu"));
//        hs.add(new Student(1, "zhangsan"));
        System.out.println(s1.hashCode());
        System.out.println(s2.hashCode());
        System.out.println(s3.hashCode());
        System.out.println(s4.hashCode());
        System.out.println(s5.hashCode());
        System.out.println(s6.hashCode());
        hs.add(s1);
        hs.add(s2);
        hs.add(s3);
        hs.add(s4);
        hs.add(s5);
        hs.add(s6);
        System.out.println("----------------");
        Iterator it = hs.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }
}

class Student {
    int num;
    String name;

    Student(int num, String name) {
        this.num = num;
        this.name = name;
    }

    public int hashCode() {
        return num * name.hashCode();
    }

//    public boolean equals(Object o){
//        Student s = (Student) o;
//        return num == s.num && name.equals(s.name);
//    }

    public String toString() {
        return num + ":" + name;
    }
}
